home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / games1 / gamestuf.bas < prev    next >
BASIC Source File  |  1995-09-07  |  5KB  |  141 lines

  1. Attribute VB_Name = "GAMESTUF"
  2. Option Explicit
  3. '--------------------------------------------------
  4. ' Global variables, constants and declaration.
  5. '--------------------------------------------------
  6.  
  7. ' Functions and constants used to play sounds.
  8. Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
  9. Declare Function sndStopSound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszNull As Long, ByVal uFlags As Long) As Long
  10.  
  11. Global Const SND_SYNC = &H0
  12. Global Const SND_ASYNC = &H1
  13. Global Const SND_NODEFAULT = &H2
  14. Global Const SND_MEMORY = &H4
  15. Global Const SND_LOOP = &H8
  16. Global Const SND_NOSTOP = &H10
  17.  
  18. ' Color Constants
  19. Global Const DARK_GRAY = &H808080
  20. Global Const WHITE = &HFFFFFF
  21. Global Const BLACK = &H0
  22.  
  23. ' KeyCode constants
  24. Global Const KEY_LEFT = &H25
  25. Global Const KEY_RIGHT = &H27
  26.  
  27. ' 3D effect constants
  28. Global Const BORDER_INSET = 0
  29. Global Const BORDER_RAISED = 1
  30.  
  31. ' A general purpose data structure used for tracking bitmaps.
  32. ' This structure can also be passed to Windows API calls requiring
  33. ' a RECT (rectangle structure).
  34. Type tBitMap
  35.     Left As Long
  36.     Top As Long
  37.     Right As Long
  38.     Bottom As Long
  39.     Width As Long
  40.     Height As Long
  41. End Type
  42.  
  43. ' Windows GDI Bitmap API constants and functions
  44. Global Const SRCCOPY = &HCC0020
  45. Global Const SRCINVERT = &H660046
  46. Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
  47.  
  48. ' Windows API rectangle functions
  49. Declare Function IntersectRect Lib "user32" (lpDestRect As tBitMap, lpSrc1Rect As tBitMap, lpSrc2Rect As tBitMap) As Long
  50.  
  51. ' Two Windows API calls used to read and write private .INI files.
  52. Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
  53. Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
  54.  
  55.  
  56. Sub Make3D(pic As Form, ctl As Control, ByVal BorderStyle As Integer)
  57. '--------------------------------------------------
  58. ' Wrap a 3D effect around a control on a form.
  59. '--------------------------------------------------
  60. Dim AdjustX As Integer, AdjustY As Integer
  61. Dim RightSide As Single
  62. Dim BW As Integer, BorderWidth As Integer
  63. Dim LeftTopColor As Long, RightBottomColor As Long
  64. Dim i As Integer
  65.  
  66.     If Not ctl.Visible Then Exit Sub
  67.  
  68.     AdjustX = Screen.TwipsPerPixelX
  69.     AdjustY = Screen.TwipsPerPixelY
  70.  
  71.     BorderWidth = 3
  72.  
  73.     Select Case BorderStyle
  74.     Case 0: ' Inset
  75.         LeftTopColor = DARK_GRAY
  76.         RightBottomColor = WHITE
  77.     Case 1: ' Raised
  78.         LeftTopColor = WHITE
  79.         RightBottomColor = DARK_GRAY
  80.     End Select
  81.     
  82.  
  83.     ' Set the top shading line.
  84.     For BW = 1 To BorderWidth
  85.         ' Top
  86.         pic.CurrentX = ctl.Left - (AdjustX * BW)
  87.         pic.CurrentY = ctl.Top - (AdjustY * BW)
  88.         pic.Line -(ctl.Left + ctl.Width + (AdjustX * (BW - 1)), ctl.Top - (AdjustY * BW)), LeftTopColor
  89.         ' Right
  90.         pic.Line -(ctl.Left + ctl.Width + (AdjustX * (BW - 1)), ctl.Top + ctl.Height + (AdjustY * (BW - 1))), RightBottomColor
  91.         ' Bottom
  92.         pic.Line -(ctl.Left - (AdjustX * BW), ctl.Top + ctl.Height + (AdjustY * (BW - 1))), RightBottomColor
  93.         ' Left
  94.         pic.Line -(ctl.Left - (AdjustX * BW), ctl.Top - (AdjustY * BW)), LeftTopColor
  95.     Next
  96. End Sub
  97.  
  98. Function NoiseGet(ByVal FileName) As String
  99. '------------------------------------------------------------
  100. ' Load a sound file into a string variable.
  101. '------------------------------------------------------------
  102. Dim buffer As String
  103. Dim f As Integer
  104. Dim SoundBuffer As String
  105.  
  106.     On Error GoTo NoiseGet_Error
  107.  
  108.     buffer = Space$(1024)
  109.     SoundBuffer = ""
  110.     f = FreeFile
  111.     Open FileName For Binary As f
  112.     Do While Not EOF(f)
  113.         Get #f, , buffer     ' Load in 1K chunks
  114.         SoundBuffer = SoundBuffer & buffer
  115.     Loop
  116.     Close f
  117.     NoiseGet = Trim$(SoundBuffer)
  118. Exit Function
  119.  
  120. NoiseGet_Error:
  121.     SoundBuffer = ""
  122.     Exit Function
  123. End Function
  124.  
  125. Sub NoisePlay(SoundBuffer As String, ByVal PlayMode As Integer)
  126. '------------------------------------------------------------
  127. ' Plays a sound previously loaded into memory with function
  128. ' NoiseGet().
  129. '------------------------------------------------------------
  130. Dim retcode As Integer
  131.     
  132.     If SoundBuffer = "" Then Exit Sub
  133.  
  134.     ' Stop any sound that may currently be playing.
  135.     retcode = sndStopSound(0, SND_ASYNC)
  136.  
  137.     ' PlayMode should be SND_SYNC or SND_ASYNC
  138.     retcode = sndPlaySound(ByVal SoundBuffer, PlayMode Or SND_MEMORY)
  139. End Sub
  140.  
  141.